package com.maegul.wui.components;

import java.io.Serializable;
import java.text.NumberFormat;
import java.util.List;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.Model;

import com.maegul.dao.entities.MediaItem;
import com.maegul.wui.MaegulSession;

public class ShoppingCartPanel extends Panel{
	
	private static final long serialVersionUID = 1L;

	public ShoppingCartPanel(String id) {
		super(id);

		add(new Label("numitems", new Model<Integer>(){

			private static final long serialVersionUID = 1L;

			@Override
			public Integer getObject() {
				return MaegulSession.get().getCart().size();
			}
			
		}));
		
		add(new Label("total", new Model<Serializable>() {

			private static final long serialVersionUID = 1L;

			@Override
			public Serializable getObject() {
				NumberFormat nf = NumberFormat.getCurrencyInstance();
				List<MediaItem> cart = MaegulSession.get().getCart();
				double total = 0;
				
				for (MediaItem mediaItem : cart) {
					System.out.println(cart.size());
					System.out.println(mediaItem);
					System.out.println(cart.get(0));
					total += mediaItem.getPrice();
				}
				
				return nf.format(total);
			}
		}));
	}


}
